﻿@using QLNS;
@{
    ViewBag.Title = "Tìm Kiếm Tổng Quát";
    Layout = "~/Views/Shared/_Home.cshtml";
    List<SelectListItem> selectListDSChuyenMon = new List<SelectListItem>();
    List<ChuyenMon> dschuyenmon = ViewBag.DSChuyenMon;
    SelectListItem itemChuyenMon = new SelectListItem();
    itemChuyenMon.Text = "Tất Cả";
    itemChuyenMon.Value = "0";
    selectListDSChuyenMon.Add(itemChuyenMon);
    foreach(var i in dschuyenmon){
        itemChuyenMon = new SelectListItem();
        itemChuyenMon.Text = i.Ten;
        itemChuyenMon.Value = i.ID.ToString();
        selectListDSChuyenMon.Add(itemChuyenMon);
    }

    List<SelectListItem> selectListDSLyLuan = new List<SelectListItem>();
    List<LyLuan> dslyluan = ViewBag.DSLyLuan;
    SelectListItem itemLyLuan = new SelectListItem();
    itemLyLuan.Text = "Tất Cả";
    itemLyLuan.Value = "0";
    selectListDSLyLuan.Add(itemLyLuan);
    foreach (var i in dslyluan)
    {
        itemLyLuan = new SelectListItem();
        itemLyLuan.Text = i.Ten;
        itemLyLuan.Value = i.ID.ToString();
        selectListDSLyLuan.Add(itemLyLuan);
    }

    List<SelectListItem> selectListDSQLNN = new List<SelectListItem>();
    List<QLNhaNuoc> dsqlnn = ViewBag.DSQLNN;
    SelectListItem itemQLNN = new SelectListItem();
    itemQLNN.Text = "Tất Cả";
    itemQLNN.Value = "0";
    selectListDSQLNN.Add(itemQLNN);
    foreach (var i in dsqlnn)
    {
        itemQLNN = new SelectListItem();
        itemQLNN.Text = i.Ten;
        itemQLNN.Value = i.ID.ToString();
        selectListDSQLNN.Add(itemQLNN);
    }

    List<SelectListItem> selectListDSNhomNgach = new List<SelectListItem>();
    List<BangMaNgach> dsmangach = ViewBag.DSMaNgach;
    SelectListItem itemMaNgach = new SelectListItem();
    itemMaNgach.Text = "Tất Cả";
    itemMaNgach.Value = "0";
    selectListDSNhomNgach.Add(itemMaNgach);
    foreach (var i in dsmangach)
    {
        itemMaNgach = new SelectListItem();
        itemMaNgach.Text = i.TenNgach;
        itemMaNgach.Value = i.MaNgach.ToString();
        selectListDSNhomNgach.Add(itemMaNgach);
    }
    
    // List root Dept
    List<SelectListItem> selectListDSPhongBan = new List<SelectListItem>();
    List<PhongBan> root = ViewBag.DsPhongBan;
    if (root.Count > 0)
    {


        //Cap 1 la Don vi       
        foreach (var r in root)
        {
            SelectListItem itemr = new SelectListItem();
            itemr.Text = r.TenPhongBan;
            itemr.Value = r.ID.ToString();
            //if (dt.IDParent == r.ID)
            //{
            //    itemr.Selected = true;
            //}
            selectListDSPhongBan.Add(itemr);
            List<PhongBan> root1 = QLNS.Models.PhongBanModels.GetDSPhongBan(r.ID);
            if (root1.Count > 0)
            {
                foreach (var r1 in root1)
                {
                    SelectListItem itemr1 = new SelectListItem();
                    itemr1.Text = r1.TenPhongBan;
                    itemr1.Value = r1.ID.ToString();
                    //itemr1.Selected = true;
                    //if (dt.IDParent == r1.ID)
                    //{
                    //    itemr1.Selected = true;
                    //}
                    selectListDSPhongBan.Add(itemr1);
                    List<PhongBan> root2 = QLNS.Models.PhongBanModels.GetDSPhongBan(r1.ID);
                    if (root2.Count > 0)
                    {
                        foreach (var r2 in root2)
                        {
                            SelectListItem itemr2 = new SelectListItem();
                            itemr2.Text = r2.TenPhongBan;
                            itemr2.Value = r2.ID.ToString();
                            //if (dt.IDParent == r2.ID)
                            //{
                            //    itemr2.Selected = true;
                            //}
                            selectListDSPhongBan.Add(itemr2);
                            List<PhongBan> root3 = QLNS.Models.PhongBanModels.GetDSPhongBan(r2.ID);
                            if (root3.Count > 0)
                            {
                                foreach (var r3 in root3)
                                {
                                    SelectListItem itemr3 = new SelectListItem();
                                    itemr3.Text = r3.TenPhongBan;
                                    itemr3.Value = r3.ID.ToString();
                                    //if (dt.IDParent == r3.ID)
                                    //{
                                    //    itemr3.Selected = true;
                                    //}
                                    selectListDSPhongBan.Add(itemr3);
                                    List<PhongBan> root4 = QLNS.Models.PhongBanModels.GetDSPhongBan(r3.ID);
                                    if (root4.Count > 0)
                                    {
                                        foreach (var r4 in root4)
                                        {
                                            SelectListItem itemr4 = new SelectListItem();
                                            itemr4.Text = r4.TenPhongBan;
                                            itemr4.Value = r4.ID.ToString();
                                            //if (dt.IDParent == r4.ID)
                                            //{
                                            //    itemr4.Selected = true;
                                            //}
                                            selectListDSPhongBan.Add(itemr4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
@using (Html.BeginForm("Index", "Search", FormMethod.Post))
{
    <div class="toolbar">
        <ul>
            <li><input class="tbtnBack" type="button" value="Quay về" onclick="javascript:history.back()"/>
            </li>
            <li><input class="tbtnSave" type="submit" value="Lưu" onclick="return false" id="btnSearch" /> 
            </li>
        </ul>
        <div class="ttitle">Tìm kiếm tổng quát</div>
    </div>
    <table width="500" border="1">
        <tr>
            <td>
                Họ tên
            </td>
            <td>@Html.TextBox("HoTenCanBo")
            </td>
        </tr>
         <tr>
            <td>
                Phòng ban
            </td>
            <td>
                @Html.DropDownList("DanhSachPhongBan", selectListDSPhongBan)
            </td>
        </tr>
         <tr>
            <td>
                Ngạch công chức
            </td>
            <td>
                @Html.DropDownList("MaNgach", selectListDSNhomNgach)
            </td>
        </tr>
        <tr>
            <td>
                Trình độ học vần
            </td>
            <td>
                @Html.DropDownList("TrinhDoHocVan", selectListDSChuyenMon)
            </td>
        </tr>
          <tr>
            <td>
                Trình độ lý luận
            </td>
            <td>
                @Html.DropDownList("TrinhDoLyLuan", selectListDSLyLuan)
            </td>
        </tr>
         <tr>
            <td>
                Trình độ quản lý nhà nước
            </td>
            <td>
                @Html.DropDownList("TrinhDoQLNN", selectListDSQLNN)
            </td>
        </tr>
       
    </table>
     <div id="jqxgridcontent"></div>
}
<script type="text/javascript">
    $('#btnSearch').click(function () {
        var HoTen = $.trim($('#HoTenCanBo').val());
        var PhongBan = $('#DanhSachPhongBan').val();
        var MaNgach = $('#MaNgach').val();
        var TrinhDoHocVan = $('#TrinhDoHocVan').val();
        var TrinhDoLyLuan = $('#TrinhDoLyLuan').val();
        var TrinhDoQLNN = $('#TrinhDoQLNN').val();
        var string = PhongBan + "," + HoTen + "," + MaNgach + "," + TrinhDoHocVan + "," + TrinhDoLyLuan + "," + TrinhDoQLNN;
        var source = {
            datatype: "json",
            datafields: [
                { name: 'IDCanBo' },
                 { name: 'HoTenCanBo' },
                { name: 'NgaySinh', type: 'date' },
                { name: 'MaNgachCC' },
                { name: 'TenNgachCC' },
                { name: 'BacLuong' },
                { name: 'HeSoLuong' },
                { name: 'TenChucVu' }
            ],
            type: 'POST',
            id: 'IDCanBo',
            url: '/Search/GetSearchPaging/' + string,
            root: 'Rows',
            sort: function () {
                $("#jqxgridcontent").jqxGrid('updatebounddata', 'sort');
            }
        };
        var dataAdapter = new $.jqx.dataAdapter(source,
                {
                    downloadComplete: function (data) {
                        source.totalrecords = data.TotalRows;
                    }
                }
            );
        $("#jqxgridcontent").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,
                theme: 'darkblue',
                autoheight: true,
                pageable: true,
                virtualmode: true,
                sortable: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgridcontent").jqxGrid('hidecolumn', 'IDCanBo');
                },
                columns:
                 [
                    { text: 'ID', editable: false, datafield: 'IDCanBo', width: 0 }, 
                      { text: 'Họ và Tên', editable: false, datafield: 'HoTenCanBo', width: '20%' },
                      { text: 'Chức Vụ', editable: false, datafield: 'TenChucVu', width: '10%' },
                       { text: 'Ngày Sinh', editable: false, datafield: 'NgaySinh', cellsformat: 'dd-MM-yyyy', width: '10%' },
                       { text: 'Mã Ngạch', editable: false, datafield: 'MaNgachCC', width: '10%' },
                       { text: 'Tên Ngạch', editable: false, datafield: 'TenNgachCC', width: '20%' },
                       { text: 'Bậc Lương', editable: false, datafield: 'BacLuong', width: '10%' },
                       { text: 'Hệ Số Lương', editable: false, datafield: 'HeSoLuong', width: '10%' },
                      { text: 'Edit', datafield: 'Edit', columntype: 'button', pinned: true, width: '10%',
                          cellsrenderer: function () {
                              return "Edit"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Update/' + dataRecord.IDCanBo + '/';
                          }
                      }
                  ]
            });
    });
</script>
